<template>
  <div id="scoreDetails" class="mainContent">
    <h2 class="title"><span>{{$route.query.scoreName}}</span></h2>
    <div class="vsContent">
      <div class="vsThead">
        <table class="table">
          <thead>
            <tr>
              <th class="text-center" width="33%">评估时间</th>
              <th class="text-center" width="33%">评估人</th>
              <th class="text-center" width="33%">评估分值</th>
            </tr>
          </thead>
        </table>
      </div>
      <div class="vsTbody" v-if="scoreData.length">
        <table class="table table-striped" >
          <tbody>
            <tr v-for="item in scoreData">
              <td class="text-center" width="33%">{{item.Time_Grade | filterDateT}}</td>
              <td class="text-center" width="33%">{{item.GradeName}}</td>
              <td class="text-center" width="33%">{{item.GradeValue}}</td>
            </tr>
          </tbody>
        </table>
      </div>
    </div>
      <lineEcharts v-if="height!=''&& itemData.length != 0" :style="{'height': height}"  class="line" :height="height" :name="$route.query.scoreName+'趋势图'" :items="itemData" ></lineEcharts>
    <loading v-if="scoreData.length==0 ||  JSON.stringify(itemData)=='{}'  "></loading>
  </div>
</template>
<script>
  import lineEcharts from '@/components/echarts/lineEcharts'
  import loading from '@/components/loading/loading'
  import { apiPatientScoreList } from '@/api/api'
  export default {
    data() {
      return {
        height: '',
        itemData:[],
        scoreData: [],
      }
    },
    mounted() {
      this.getPatientScoreList();
    },
    methods: {
      getHeight() {
        this.height = $('#scoreDetails').height() - $('.vsTbody').height() - 75 + 'px'
      },
      getPatientScoreList() {
        apiPatientScoreList({
          patientIdIn: this.$store.getters.ID,
          eventName : this.$route.query.scoreName
        })
          .then(res => {
            if (res.Status == 1) {
              this.scoreData = JSON.parse(res.Data);
              //console.log(this.scoreData)
              this.itemData = [];
              for (var item of JSON.parse(res.Data)) {
                this.itemData.push({ date: this.filterDate(item.Time_Grade), value: item.GradeValue })

              }
              this.$nextTick(function () {
                this.getHeight();
              })
            }
          })
      },
      filterDate(time) {
        if (!time) {
          return '';
        }
        else {
          time = time.replace(/\//g, '-');
          time = time.replace(/T/g, ' ');
          return time.substring(5, 16);
        }
      },
    },
    components: {
      lineEcharts,
      loading
    }
}
</script>
<style scoped>
  #scoreDetails {
    height:100%;
    padding: 20px 0;
  }

  .title {
    font-size: 18px;
    padding-left: 40px;
  }

    .title span:before {
      content: '';
      display: inline-block;
      width: 3px;
      height: 20px;
      border-radius: 8px;
      margin-right: 8px;
      background: #11a7f3;
      vertical-align: text-top;
    }

  .table > thead > tr > th {
    border-bottom: none;
  }

  .vsThead, .vsTbody {
    width: 80%;
    /*border:1px solid #f4f4f4;*/
    border-top: none;
  }

  .vsContent {
    margin-top: 10px;
    padding-left: 40px;
  }

  .table {
    margin-bottom: 0;
  }

  .vsThead thead tr {
    height: 42px;
    line-height: 42px;
    background-color: #11a7f3;
    color: #fff;
  }

  .vsThead > thead > tr > th {
    border-bottom: none;
  }

  .vsTbody {
    max-height: calc(100vh - 600px);
    overflow-y: auto;
    border: 1px solid #ddd;
  }

    .vsTbody tbody tr td {
      padding: 10px 0;
      vertical-align: middle;
      border-top: 1px solid #ddd;
      color: #333;
      border-right: 1px solid #ddd;
    }

      .vsTbody tbody tr td:last-child {
        border-right: none;
      }

    .vsTbody tbody > tr:first-child > td {
      border-top: none;
    }

  .line {
    margin-top: 20px;
  }
</style>
